function packupKeyboard() {
    $(".moreDiv").css("display","none");

    $('.desc').blur();
}
//$(window).scroll(function (event) {
//    packupKeyboard();
//});

//时间
var tempTime = {};
var min_sec;            //分:秒
var whole_time;         //2016.10.26 12:33
var hours_min;          //时:分
var whole_day;          //2016.10.26
var year_mon_day;       //2016-10-26
var day_min;            //10月26日 12:33
var timestamp;           //时间戳
var mon_day;
function initDate(date) {
    tempTime = {
        year: date.getFullYear(),
        month: (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1),
        day: date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
        hours: date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
        min: date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
        sec: date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(),
    };
    whole_time = tempTime.year + "." + tempTime.month + "." + tempTime.day + " " + tempTime.hours + ":" + tempTime.min;
    whole_day = tempTime.year + "." + tempTime.month + "." + tempTime.day;
    hours_min = tempTime.hours + ":" + tempTime.min;
    min_sec = tempTime.min + ":" + tempTime.sec;
    year_mon_day = tempTime.year + "-" + tempTime.month + "-" + tempTime.day;
    day_min = tempTime.month + "月" + tempTime.day + "日" + " " + tempTime.hours + ":" + tempTime.min;
    mon_day = tempTime.month + "月" + tempTime.day + "日";
}

//时间转换时间戳
function initTimestamp(date) {
    var time = date + " 00:00:00";
    time = new Date(Date.parse(new Date(date)));
    timestamp = time.getTime();
}

//API调用
function API_Func(url, type, data, ISloadshow, beforeSend, success, fail) {

    $.ajax({
        url: apiurl + url,
        type: type,
        data: data,
        dataType: "json",
        success: function (d) {
            if (ISloadshow) {
                $(".loading").hide();
            }
            var data = '';
            if (typeof d == "object") {
                data = d;
            }
            else {
                data = JSON.parse(d);
            }

            success(data);
        },
        beforeSend: function () {
            if (ISloadshow) {

                $(".loading").show();
            }
            beforeSend();
        },
        error: function (d) {
            fail(d);
        }
    });
}
//返回上一级
function goback() {
    history.back(-1);
}
//跳到新建页面
function goAdd() {
    location.href = "add.html";
}


//上传图片
$(document).on('change', '#pic', function (d) {
    var formdata = new FormData($("#form")[0]);
    formdata.append("type", "0");
    formdata.append("names", "img");
    var file = this.files[0];
    if (file != undefined){
        var file_name = file.name;
        var type = file_name.split(".");
        type = type[type.length - 1].toLowerCase();

        //if (type == "jpg" || type == "png" || type == "jpeg" || type == "bmp") {
        if(checkImageType(file_name)==true) {

            var pass = $(".div_img_img .img_up").length < 9 ? true : false;

            if (!pass) {
                var obj = $('.pop-up');
                obj.text('最多只能选择9张照片');
                obj.fadeIn();
                obj.fadeOut(3000);
            }

            if (pass) {
                //拿到当前上传图片的对象
                var _currentimg;
                $.ajax({
                    beforeSend: function () {
                        $(".div_img_img").append("<div><img class='img_up' src='public/img/basic/loading.gif' /><img class='red_delete' src='public/img/subject/redDelete.png'/></div>");

                        //拿到最后一张的图片对象,就是当前上传的对象
                        _currentimg = $('.div_img_img div .img_up').last();
                    },
                    type: 'POST',
                    url: apiurl + '/global/upload',
                    data: formdata,
                    cache: false,
                    processData: false,
                    contentType: false,
                    mimeType: "multipart/form-data",
                    success: function (d) {
                        var data_url = JSON.parse(d).data;
                        _currentimg.attr("src", "http://" + data_url + "");

                        //删除图片
                        $('.red_delete').unbind('click').on('click', function () {
                            var _self = $(this);
                            _self.parent().remove();
                        });
                    }
                })
            }
            else {

            }
        }else {
            $(".call_back_success").text("不支持该图片类型!").fadeIn();
            setTimeout(function(){
                $(".call_back_success").fadeOut(1000);
            },1000);
        }
    }
    var imgInput = $('#pic');
    imgInput.replaceWith(imgInput.val('').clone(true));
});


(function ($) {
    $(window).resize(function () {          //当浏览器大小变化时
        setHtmlFontSize(720);
    });

    //初始化执行
    setHtmlFontSize(720);
    //动态设置html元素的font-size的方法
    function setHtmlFontSize(num) {
        //页面的宽度，其中17为页面默认的导航条的宽度
        var _w = document.documentElement.clientWidth;
        var fontSize = 12 * _w / num;
        //if (fontSize<12)
        //    fontSize = 12;
        $('html').css('fontSize', fontSize);
    }

})(jQuery);




